﻿using System;
using UnityEngine;

namespace Assets.Scripts.UI.SuperListView
{
    class UIContentFixPos : MonoBehaviour
    {
        public enum Direction
        {
            Horizontal = 0,
            Vertical = 1
        }

        public float mMinFix = 0.5f;
        public Direction mDirection = Direction.Vertical;

        RectTransform rect;

        void Start()
        {
            rect = gameObject.GetComponent<RectTransform>();
        }

        private void LateUpdate()
        {
            if (rect == null) return;
            if (mDirection == Direction.Vertical)
            {
                if (Math.Abs(rect.anchoredPosition.y) < mMinFix)
                {
                    Vector3 nowVer3 = new Vector3(rect.anchoredPosition.x, 0, 0);
                    rect.anchoredPosition = nowVer3;
                }
            }
            else
            {
                if (Math.Abs(rect.anchoredPosition.x) < mMinFix)
                {
                    Vector3 nowVer3 = new Vector3(0, rect.anchoredPosition.y, 0);
                    rect.anchoredPosition = nowVer3;
                }
            }
        }
    }
}
